package com.fxl.service;

import com.fxl.dao.User2Mapper;
import com.fxl.dao.UserRepository;
import com.fxl.entity.User;
import com.fxl.entity.User2;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;
    @Autowired
    private User2Mapper user2Mapper;

    public List<User2> findAll(){
        return user2Mapper.findAll();
    }

    public User2 findById(Integer id){
        return user2Mapper.findById(id);
    }

    public List<User2> findByUsername(String username){
        return user2Mapper.findByUsername(username);
    }

    public List<User> getAllUsers() {
        return userRepository.findAll();
    }

    public User getUserById(Integer id) {
        return userRepository.findById(id).orElse(null);
    }

    public List<User> getUsersByUsername(String username) {
        return userRepository.findByUsername(username);
    }
    public User addUser(User user) {
        return userRepository.save(user);
    }
    public void deleteUser(Integer id) {
        userRepository.deleteById(id);
    }
}
